// 我首页
//  MZY_SelfViewController.m
//  FullHouse
//
//  Created by dllo on 16/1/15.
//  Copyright © 2016年 yy. All rights reserved.
//

#import "MZY_SelfViewController.h"
#import "MZY_informationCell.h"
#import "MZY_myRenovate.h"
#import "MZY_function.h"
#import "MZY_AttentionViewController.h"
#import "MZY_DeleteViewController.h"
#import "DKNightVersion.h"

#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height

@interface MZY_SelfViewController ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic, retain)UITableView *tableView;
@property(nonatomic, retain)NSArray *picArr;
@property(nonatomic, retain)NSMutableArray *textArr;

@end

@implementation MZY_SelfViewController

- (void)dealloc
{
    [self.tableView release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self createView];
}

- (void)createView{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT - 49 - 64) style:UITableViewStyleGrouped];
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    [self.tableView registerClass:[MZY_informationCell class] forCellReuseIdentifier:@"information"];
    [self.tableView registerClass:[MZY_myRenovate class] forCellReuseIdentifier:@"renovate"];
    [self.tableView registerClass:[MZY_function class] forCellReuseIdentifier:@"function"];
    [self.tableView release];
    
    self.picArr = [NSMutableArray arrayWithObjects:@[@"",@"iconfont-xiaoxi-1.png",@"iconfont-xiaoxi-2.png",@"iconfont-guanzhu.png"],@[],@[@"iconfont-kehuxuqiu.png",@"iconfont-yuyue.png"],@[@"iconfont-pinglun.png"],@[@"iconfont-gerenzhongxinwodeziliao.png"],@[@"iconfont-shezhi.png"],@[@"iconfont-yejianzhuanhuan.png"], nil];
    
    self.textArr = [NSMutableArray arrayWithObjects:@[@"",@"我的消息",@"我的私信",@"关注动态"],@[],@[@"我的装修需求",@"我的预约"],@[@"我发出的评论"],@[@"修改个人资料"],@[@"设置"],@[@"夜间模式"], nil];
}

#pragma mark "tableView"的第一个必须执行的方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 4;
    }else if (section == 1){
        return 1;
    }else if (section == 2){
        return 2;
    }else{
        return 1;
    }
}

#pragma mark "tableView"的第二个必须执行的方法
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0 && indexPath.section == 0) {
        MZY_informationCell *cell = [tableView dequeueReusableCellWithIdentifier:@"information" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellEditingStyleNone;
        cell.faceImageView.image = [UIImage imageNamed:@"4.jpg"];
        cell.faceImageView.layer.cornerRadius = 40;
        cell.faceImageView.layer.masksToBounds = YES;
        cell.nickLabel.text = @"天才";
        cell.nickLabel.textColor = [UIColor lightGrayColor];
        cell.rightImageView.image = [UIImage imageNamed:@"iconfont-you.png"];
        return cell;
    }else if (indexPath.row == 0 && indexPath.section == 1){
        MZY_myRenovate *cell = [tableView dequeueReusableCellWithIdentifier:@"renovate" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellEditingStyleNone;
        cell.titleLabel.text = @"我的装修";
        cell.titleLabel.textColor = [UIColor lightGrayColor];
        cell.renovateImageView.image = [UIImage imageNamed:@"my.png"];
        return cell;
    }else{
        MZY_function *cell = [tableView dequeueReusableCellWithIdentifier:@"function" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellEditingStyleNone;
        
        NSArray *arrPic = self.picArr[indexPath.section];
        cell.logoImageView.image = [UIImage imageNamed:arrPic[indexPath.row]];
        NSArray *arrText = self.textArr[indexPath.section];
        cell.titleLabel.text = arrText[indexPath.row];
        cell.titleLabel.textColor = [UIColor lightGrayColor];
        //字体颜色
        cell.textLabel.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);
        //cell颜色
        cell.dk_backgroundColorPicker = DKColorWithRGB(0xffffff, 0x343434);
        return cell;
    }
    
}

#pragma mark 设置"tableView"里有多少个分区
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 7;
}

#pragma mark 返回行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0 && indexPath.section == 0) {
        return 100;
    }else if (indexPath.row == 0 && indexPath.section == 1){
        return 150;
    }else{
        return 50;
    }
}

#pragma mark 设置分区的标题
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.01;
}

#pragma mark 设置"cell"之间"headerView"的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return 0.01;
    }else{
        return 15;
    }
}

#pragma mark 设置"headerView"颜色
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *headerView = [[UIView alloc]init];
    headerView.backgroundColor = [UIColor lightGrayColor];
    headerView.alpha = 0.5;
    return headerView;
}

#pragma mark "tableView"的点击方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0 && indexPath.row == 3) {
        self.hidesBottomBarWhenPushed = YES;
        MZY_AttentionViewController *attVC = [[MZY_AttentionViewController alloc]init];
        [self.navigationController pushViewController:attVC animated:YES];
        self.hidesBottomBarWhenPushed = NO;
    }else if (indexPath.section == 5 && indexPath.row == 0){
        self.hidesBottomBarWhenPushed = YES;
        MZY_DeleteViewController *delVC = [[MZY_DeleteViewController alloc]init];
        [self.navigationController pushViewController:delVC animated:YES];
        self.hidesBottomBarWhenPushed = NO;
    }else if (indexPath.section == 6 && indexPath.row == 0){
        if ([DKNightVersionManager currentThemeVersion] == DKThemeVersionNight) {
            [DKNightVersionManager dawnComing];
        } else {
            [DKNightVersionManager nightFalling];
        }
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
